<?php
/**
 * 项目：红河移动工程过程管理系统
 *
 * 公司：红河移动分公司
 *
 * @author 李朝应
 *
 * E-mail:lichaoying.hh@163.com
 *
 */
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Project_model extends CI_Model {
 function __construct()
    {
        parent::__construct();
    }
 function getProjectWithPcode($pcode){
     $this->db->where("pcode",$pcode);
     $query = $this->db->get('project');
     if ($query->num_rows() > 0){return TRUE;}else{ return FALSE; }  
 }
 function getProjectWithPcodeOfEdit($pid,$pcode){
     $this->db->where("pid !=",$pid);
     $this->db->where("pcode",$pcode);
     $query = $this->db->get('project');
     if ($query->num_rows() > 0){return TRUE;}else{ return FALSE; }    
 }
function getProiectAll($a,$b){
  $this->db->select('pid,pcode,pname,name,constructionState,pyear,members.uid as uid');
  $this->db->from('project');
  $this->db->join('members', 'project.uid = members.uid');
  $this->db->limit($b, $a);
  return $this->db->get();
}
function getProiectTotal(){
 return  $this->db->count_all("project");    
}
function getProiectAllByUid($login){
  $this->db->select('pid,pcode,pname,name,constructionState,pyear,members.uid as uid');
  $this->db->from('project');
  $this->db->join('members', 'project.uid = members.uid');
  $this->db->where('members.login',$login);
  return $this->db->get();
}
function getProiectAllByQuery($pcode,$name,$pm,$years,$state){
  $this->db->select('pid,pcode,pname,name,constructionState,pyear,members.uid as uid');
  $this->db->from('project');
  $this->db->join('members', 'project.uid = members.uid'); 
  if($pcode<>""){$this->db->like('pcode', $pcode);}
  if($name<>""){$this->db->like('pname', $name);}
  if($pm<>""){$this->db->like('members.name', $pm);}
  if($years<>""){$this->db->where('pyear', substr($years,0,4));}
  if($state<>""){ if ($state=="1"){$state=TRUE;}else{$state=FALSE;}  $this->db->where('constructionState', $state);}
  return $this->db->get();
}
function getProjectByPid($pid){
   return $this->db->where("pid", $pid)->get('project')->row_array();   
}
function getProjectByPcode($pcode){
   $this->db->from('project');
   $this->db->join('members', 'project.uid = members.uid');
   return $this->db->where("pcode", $pcode)->get()->row_array();   
}
function setProjectDelByPid($pid){
  $this->db->where('pid', $pid);
  $this->db->delete('project');   
 return $this->db->affected_rows() ;   
}
function getPcodeAuth($pcode){
 $this->db->select("pname as name");
 $this->db->where("pcode", $pcode);
 $query = $this->db->get('project');
 if ($query->num_rows() > 0){return TRUE;}else{return FALSE;}   
}

function getPnameWithPcodeAuth($pcode){
 $this->db->select("pname as name");
 $this->db->where("pcode", $pcode);
 return $this->db->get('project')->row()->name;
}
function getPmWithPcodeAuth($pcode){
  $this->db->select('name');
  $this->db->from('project');
  $this->db->join('members', 'project.uid = members.uid'); 
  $this->db->where("pcode", $pcode);
 return $this->db->get()->row()->name;
}
function getPidByPcode($pcode){
 $this->db->select("pid");
 $this->db->where("pcode", $pcode);
 return $this->db->select("pid")->get('project')->row()->pid;
}
function getUidByPcode($pcode){
return $this->db->select("uid")->where("pcode", $pcode)->get('project')->row()->uid;    
}

}//end class